package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.MessageProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @Author : 李红磊
 * @Date : 2021/05/19/22:46
 * @Description :
 */

@EnableBinding(Source.class)//定义消息的推送管道
public class MessageProviderServiceImpl implements MessageProviderService {

    @Autowired
    private MessageChannel output;//这就是那个发送消息用的管道


    @Override
    public String send() {
        String uuid= UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(uuid).build());//封装消息
        System.out.println("发送成功"+uuid);
        return null;
    }


}

